package com.example.lib_base.net

import com.example.lib_base.entity.AddCartEntity
import com.example.lib_base.entity.CartEntity
import com.example.lib_base.entity.CategoryEntity
import com.example.lib_base.entity.CommentEntity
import com.example.lib_base.entity.CouponEntity
import com.example.lib_base.entity.CreateOrderEntity
import com.example.lib_base.entity.DetailEntity
import com.example.lib_base.entity.GetPreOrderEntity
import com.example.lib_base.entity.GoodsEntity
import com.example.lib_base.entity.IndexEntity
import com.example.lib_base.entity.LoginEntity
import com.example.lib_base.entity.OrderEntity
import com.example.lib_base.entity.PayEntity
import com.example.lib_base.entity.PreOrderEntity
import com.example.lib_base.entity.Res
import com.example.lib_base.entity.SendCodeEntity
import com.example.lib_base.entity.UploadEntity
import com.example.lib_base.entity.UserInfoEntity
import com.example.lib_base.param.PComment
import com.example.lib_base.param.PCreateOrder
import com.example.lib_base.param.PPay
import com.example.lib_base.param.PPreOrder
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path
import retrofit2.http.Query


interface ApiService {
    @POST(Cons.SENDCODE_URL)
    suspend fun sendCode(@Query("phone") phone: String): Res<SendCodeEntity>

    @POST(Cons.LOGIN_URL)
    suspend fun login(@Body body: RequestBody): Res<LoginEntity>

    @GET(Cons.USERINFO_URL)
    suspend fun userInfo(): Res<UserInfoEntity>

    @POST(Cons.UPDATEPWD_URL)
    suspend fun updatePwd(@Body body: RequestBody): Res<Boolean>

    @POST(Cons.LOGINPWD_URL)
    suspend fun loginPwd(@Body body: RequestBody): Res<LoginEntity>

    @GET(Cons.INDEX_URL)
    suspend fun index(): Res<IndexEntity>

    @GET(Cons.COUPON_URL)
    suspend fun coupon(
        @Query("limit") limit: String,
        @Query("page") page: String,
        @Query("type") type: String
    ): Res<CouponEntity>

    //首页商品数据
    @GET(Cons.INDEX_GOODS_URL)
    suspend fun indexGoods(
        @Path("type") type: Int,
        @Query("limit") limit: Int,
        @Query("page") page: Int
    ): Res<GoodsEntity>

    @POST(Cons.COUPON_GET_URL)
    suspend fun couponGet(@Body body: RequestBody): Res<String?>

    @GET(Cons.GOODS_URL)
    suspend fun goods(
        @Query("cid") cid: Int,
        @Query("keyword") keyword: String,
        @Query("limit") limit: Int,
        @Query("news") news: Boolean,
        @Query("page") page: Int,
        @Query("priceOrder") priceOrder: String,
        @Query("salesOrder") salesOrder: String
    ): Res<GoodsEntity>

    @GET(Cons.DETAIL_URL)
    suspend fun detail(@Path("id") id: Int, @Query("type") type: String): Res<DetailEntity>

    @POST(Cons.ADDCART_URL)
    suspend fun addCart(@Body body: RequestBody): Res<AddCartEntity>

    @GET(Cons.CART_URL)
    suspend fun cart(
        @Query("isValid") isValid: String,
        @Query("limit") limit: String,
        @Query("page") page: String
    ): Res<CartEntity>

    @POST(Cons.CART_UPDATE_URL)
    suspend fun cartUpdate(@Query("id") id: Int, @Query("number") number: Int): Res<String?>

    @POST(Cons.CART_DELETE_URL)
    suspend fun cartDelete(@Query("ids") ids: Array<Int>): Res<String?>

    @GET(Cons.CATEGORY_URL)
    suspend fun category(): Res<CategoryEntity>

    @GET(Cons.COMMENT_URL)
    suspend fun comment(
        @Path("id") id: Int,
        @Query("limit") limit: Int,
        @Query("page") page: Int,
        @Query("type") type: String
    ): Res<CommentEntity>

    @POST(Cons.PREORDER_URL)
    suspend fun preOrder(@Body pPreOrder: PPreOrder): Res<PreOrderEntity>

    @GET(Cons.GETPREODER_URL)
    suspend fun getPreOrder(@Path("preOrderNo") preOrderNo: String): Res<GetPreOrderEntity>

    @POST(Cons.CREATE_ORDER_URL)
    suspend fun createOrder(@Body pCreateOrder: PCreateOrder): Res<CreateOrderEntity>

    @POST(Cons.PAY_URL)
    suspend fun pay(@Body pPay: PPay): Res<PayEntity>

    @GET(Cons.ORDER_URL)
    suspend fun order(
        @Query("type") type: String,
        @Query("limit") limit: Int,
        @Query("page") page: Int
    ): Res<OrderEntity>

    @Multipart
    @POST(Cons.UPLOAD_URL)
    suspend fun upload(
        @Query("model") model: String,
        @Part part: MultipartBody.Part,
        @Query("pid") pid: String
    ): Res<UploadEntity>

    @POST(Cons.COMMENT_SEND_URL)
    suspend fun sendComment(@Body pComment: PComment):Res<String?>
}